package com.sjb.cp.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author:sjb
 * @CreateTime:2024-12-12
 * @Description: cos云存储配置类
 * @Version：1.0
 */
@Configuration
@Data
@ConfigurationProperties(prefix = "cos.client")
public class COSConfig {

    private String secretId;

    private String secretKey;

    private String region;

    private String host;

    private String bucket;

    @Bean
    public COSClient cosClient() {
        // 初始化身份信息
        COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);

        ClientConfig clientConfig = new ClientConfig(new Region(region));
        // 生成cos客户端
        return new COSClient(cred, clientConfig);
    }

}
